
define(function(require, exports, module) {

	var $ = require('jquery');
	var List = require('../util/list');
	require('artTemplate/artTemplate/2.0.1/template.js');
	require('jquery/jquery-json/2.4.0/jquery.json.js');
	require('jquery/jquery-form/1.0.0/jquery.form.js');
	require('jbox');
	
	
	exports.options = {
		listLink : '',
		listParams : '',
		pageLink : '',
		pageParams : ''
	};
	if($g_user.login == "false"){
		var uid = -1;
	}else{
		var uid = $g_user.id;
		// 判断用户
		exports.options.userlink = $CONFIG.base_url + "/api/user";
		exports.options.userParams = {
			"uid" : uid
		};
		var userInfor = $.get(exports.options.userlink, exports.options.userParams);
		userInfor.done(function(data) {
			if (data.user.roles == "charitarian") {
				$("#pre-trial-projects").show();
				$(".pre_project").show();
			}
		});
	}
/*不用在首页显示	// 动态加载项目分类
	var category = new List();
	category.options.template = "category-template";
	category.options.container = "#category";
	category.options.links = {
		"list" : $CONFIG.base_url + "/api/category"
	};
	category.options.params = {};
	category.load();
//动态加载项目收益类型
	var getting = $.get($CONFIG.base_url + "/api/system/project/categorylist",{"type":3});
	getting.done(function(data) {
		data={"data":data};
		var html = template.render("profit-template", data);
		$("#profit1").empty().append(html);
	});
*/
	//加载标签
	var url = $CONFIG.base_url + '/api/configure/get';
	$.get(url,function(data){
		$("#itemFirstname").text(data.itemFirstname);
		$("#itemSecname").text(data.itemSecname);
		$("#itemFname").text(data.itemFname);
	});


	// 动态加载项目分类
	var category = new List();
	category.options.template = "category-template";
	category.options.container = "#type-nav";
	category.options.links = {
		"list" : $CONFIG.base_url + "/api/category"
	};
	category.options.params = {};
	category.load();

	// 定时器
	var secs = 3;
	exports.auto_jump = function auto_jump() {
		secs = secs - 1;
		if (secs < 0) {
			return false;
		}
		if (secs == 0) {
			clearInterval(time);
			$(".letter_send_seccuss").hide();
		}
	};


	/*// 加载项目
	exports.loadProject = function(e, s) {
		var projectlist = new List();
		projectlist.options.template = "financing-project-template";
		projectlist.options.container = "#" + e;
		projectlist.options.links = {
			"list" : $CONFIG.base_url + "/api/project/list"
		};
		projectlist.options.params = {
			"p" : "1",
			"s" : "4",
			"status" : s
		};
		projectlist.load();
	};
	// 预审项目
	exports.loadProject("pre-trial-projects", "2");
	// 最需自主的
	exports.loadProject("financing-projects", "3");
	// 最需关注的
	exports.loadProject("pre-heat-projects", "4");*/
	
	// 最新上线项目
	exports.loadSort = function(by) {
		var loadSort = new List();
		loadSort.options.template = "project-template";
		loadSort.options.container = "#latest-projects";
		loadSort.options.links = {
			"list" : $CONFIG.base_url + "/api/project/sort/" + by
		};
		loadSort.options.params = {
			"p" : "1",
			"s" : "4",
			"status" : "5"
		};
		loadSort.load(function(){
			exports.turn();
		});
	};
	exports.loadSort("latest");
	
	
	exports.loadpro=function(e){
		var hotProject = new List();
		hotProject.options.template = "project-template";
		hotProject.options.container = "#" + e + "-projects";
		hotProject.options.links = {"list" : $CONFIG.base_url + "/api/project/tags"};
		hotProject.options.params = {"p" : "1","s" : "4","tags" : e};
		hotProject.load(function(){
			exports.turn();
		});
	};
	
	//筛选金牌服务
	exports.loadpro("gold");
	
	//筛选小众服务
	exports.loadpro("small");
	
	
	
	
	
	$('.sel-dl a').click(
			function() {
				$(this).addClass('discover-select').siblings().removeClass(
						'discover-select');
			});
	
	exports.loadScroll=function(){
		var hotProject = new List();
		hotProject.options.template = "carousel-template";
		hotProject.options.container = "#banner-carousel";
		hotProject.options.links = {"list" : $CONFIG.base_url + "/api/project/tags"};
		hotProject.options.params = {"p" : "1","s" : "4","tags" : "hot"};
		hotProject.load(function(){
			$("#banner-carousel .item:first").addClass("active");
			exports.turn();
		});
	};
	exports.loadScroll();
	
	$("#footer-div").css("display","block");
	
	//数字过大转换为“xx万”的形式
	exports.turn = function(){
		$("span[id=attentioncount]").each(function(){
			var val = $.trim($(this).text());
			if(val >= 1000000){
				val = val/10000;
				val = Math.round(val)
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 100000){
				val = val/1000;
				val = Math.round(val);
				val = val/10;
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 10000){
				val = val/100;
				val = Math.round(val);
				val = val/100;
				$(this).empty().append("<b>"+val+"万</b>")
			}else{
				$(this).empty().append("<b>"+val+"</b>")
			}
		})
		$("span[id=fundcurrent]").each(function(){
			var val = $.trim($(this).text());
			if(val >= 1000000){
				val = val/10000;
				val = Math.round(val)
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 100000){
				val = val/1000;
				val = Math.round(val);
				val = val/10;
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 10000){
				val = val/100;
				val = Math.round(val);
				val = val/100;
				$(this).empty().append("<b>"+val+"万</b>")
			}else{
				$(this).empty().append("<b>"+val+"</b>")
			}
		})
		$("span[id=productamount]").each(function(){
			var val = $.trim($(this).text());
			if(val >= 1000000){
				val = val/10000;
				val = Math.round(val)
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 100000){
				val = val/1000;
				val = Math.round(val);
				val = val/10;
				$(this).empty().append("<b>"+val+"万</b>")
			}
			else if(val >= 10000){
				val = val/100;
				val = Math.round(val);
				val = val/100;
				$(this).empty().append("<b>"+val+"万</b>")
			}else{
				$(this).empty().append("<b>"+val+"</b>")
			}
		})
	}
	
});